package com.ask.forMe.controller.business;

import com.ask.forMe.langchain4j.rag.loader.MyDocumentLoader;
import com.ask.forMe.model.entity.Result;
import com.ask.forMe.utils.IdGenerator;
import dev.langchain4j.data.document.Document;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import static com.ask.forMe.constant.SystemConstant.KNOWLEDGE_PATH;

@RestController
@RequestMapping
@Tag(name = "测试接口")
public class TestController {
    @Autowired
    private IdGenerator idGenerator;

    private final String filePath = KNOWLEDGE_PATH + "heading.md";

    @GetMapping("/id")
    @Operation(summary = "生成会话id")
    public Result getId(Integer userId) {
        return Result.success(idGenerator.getOrCreateConversationID(userId));
    }

    @GetMapping("/all")
    @Operation(summary = "all接口")
    public Result allTest(String filePath) {
        Document document = MyDocumentLoader.loadAndParserByDefault(filePath);
        System.out.println(document.text());
        return Result.success(document.text());
    }
}
